﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace ApartmentBillsManager.Start.Common
{
    public class Apartment
    {
        private Apartment(){}

        public Apartment(string apartmentName, ObservableCollection<Roommate> roommates, ObservableCollection<Bill> openBills, ObservableCollection<Bill> closedBills, List<BalanceRow> balance)
        {
            AptName = apartmentName;
            Roommates = roommates;
            OpenBills = openBills;
            ClosedBills = closedBills;
            Balance = balance;
        }

        public string AptName { get; set; }
        public ObservableCollection<Roommate> Roommates { get; set; }
        public ObservableCollection<Bill> OpenBills { get; set; }
        public ObservableCollection<Bill> ClosedBills { get; set; }
        public List<BalanceRow> Balance { get; set; }

        public void UpdateBalace(string payer, string payee, decimal amount)
        {
            Balance.First(row => row.RoommateName == payer).Balance -= amount;

            Balance.First(row => row.RoommateName == payee).Balance += amount;
        }
    }
}
